package com.crl.module.cmpRpc.behavior
{
	import com.crl.core.IDisposable;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class RemoteToken implements IEventDispatcher ,IDisposable
	{
		private var _eventDispatcher:EventDispatcher;
		//private var eventListeners:Dictionary;
		public function RemoteToken()
		{
			_eventDispatcher=new EventDispatcher();
			
			//eventListeners=new Dictionary(true);
		}
		
		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			/*if(useWeakReference==false){
				var list:Array=getListeners(type);
				//todo push;
			}*/
			_eventDispatcher.addEventListener(type,listener,useCapture,priority,useWeakReference);
		}
		
		/*private function getListeners(type:String):Array{
			var list:Array=eventListeners[type];
			if(list==null){
				list=[];
			}
			return list;
		}*/
		
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			_eventDispatcher.removeEventListener(type,listener,useCapture);
		}
		
		public function dispatchEvent(event:Event):Boolean
		{
			if(_eventDispatcher.hasEventListener(event.type)==false){
				return false;
			}
			return _eventDispatcher.dispatchEvent(event);
			
		}
		
		public function hasEventListener(type:String):Boolean
		{
			return _eventDispatcher.hasEventListener(type);
		}
		
		public function willTrigger(type:String):Boolean
		{
			return _eventDispatcher.willTrigger(type);
		}
		
		public function dispose():void{
			_eventDispatcher=null;
		}
	}
}